/*
 * handsfree.h - handsfree HFPD-service interface
 *
 * Copyright (C) 2010-2011 Serge Begger
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef HANDSFREE_H
#define HANDSFREE_H

#include <QWidget>
#include <QPushButton>
#include <QMessageBox>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusReply>
#include <QSettings>
#include "phonebook.h"
#include "qcarpcdialog.h"

namespace Ui {
    class handsfree;
}

class audioGateway;
class soundIO;

class handsfree : public QWidget
{
    Q_OBJECT

public:
    explicit handsfree(QWidget *parent = 0);
    ~handsfree();

    QDBusInterface *handsFree;
    QString conDevice(QString);
    QString getDevName(QString);
    QList<QString> *devList;
    QDBusObjectPath currPath;
    QString lastError, lastNumber;
    bool error;

    void startScan();
    void startHFS();
    void stopHFS();
    bool currState;

private:
    Ui::handsfree *ui;
    void createCallMessage();
    phonebook *PhoneBook;
    numPanel *numPhonePanel;
    QMessageBox *callMessage;
    myMessage *messages;
    QSettings *settings;
    QPushButton *defButton;
    QPushButton *cancelButton;
    bool incCall;
    void updateUi();
    //interface
    audioGateway *agInterface;
    soundIO *sndInterface;
    //indicators
    int service, roam, signal, battchg, voiceMail;

signals:
    void hideWidget();
    void changeState();
    void openAGW(bool);
    void muteSound(bool);

private slots:
    void updateNumber();
    void on_deleteButton_pressed();
    void on_backButton_pressed();
    void on_stCallButton_pressed();
    void on_endCallButton_pressed();
    void on_voiceCallButton_pressed();
    void on_muteButton_toggled(bool);
    void on_phoneBookButton_pressed();

    void phoneBookHidden();
    void selectNumberPhBook();

    void openAudioGW(bool);
    void indChange(QString,int);
    void callChange(unsigned char);
    void systemState(bool);
    void inquiryState(bool);
    void findDev(QString , unsigned int);
    void agAdded(QDBusObjectPath);
    void dial();
    void answer();
    void hangUp();
    void inCall(QString);
    void prnMessage(int, QString);

};


class audioGateway : public QObject
{
Q_OBJECT

public:
    explicit audioGateway(QObject *parent = 0);
    ~audioGateway();
    void createAg(QString path = QString());
    void connectAg();
    void disconnAg();
    void agAudioOpen();
    void dial(QString);
    void hangUp();
    void answer();
    void voiceRecognition(bool);
    QString queryOperator();
    bool error;
    QDBusInterface *agIfase;
    int agCurrCallState;

signals:
    void agOpen(bool);
    void indicatorChange(QString,int);
    void agCallSt(unsigned char);
    void inCall(QString);

public slots:

private:

private slots:
    void agState(unsigned char);
    void agAudioState(unsigned char);
    void indChange(QString,int);
    void agCallState(unsigned char);
    void ring(QString,int,QString,int,QString);
};

class soundIO : public QObject
{
Q_OBJECT

public:
    explicit soundIO(QObject *parent = 0);
    ~soundIO();
    QDBusInterface *soundPump;
    void agStart(QDBusObjectPath);
    void mute(bool);
    bool error;    

signals:

public slots:

private:

private slots:

};

#endif // HANDSFREE_H
